feat: Support autolinking C++ only TurboModules on Android#2387
feat: Support autolinking C++ only TurboModules on Android#2387thymikee merged 7 commits intoreact-native-community:mainfrom
Conversation
|
Thanks for sending this over @atlj this is great!
I think we should not add a new property, and instead adapt the logic to work on the existing properties: and remove the assumption that there needs to be a |
|
Hey @cortinico I've removed the property from the config. The CLI now treats a dependency that doesn't have a manifest or a build.gradle file (full details in the description) as a pure cxx dependency. |
Thanks for the sending this over. I'll try to review this in the next days. Just a heads up that things are slower than usual those days due to https://conf.react.dev/ |
szymonrybczak
left a comment
There was a problem hiding this comment.
LGTM! Thank you for contribution @atlj! 🚀
I gave it a shot inside example and it retrieves all values correctly 🙌
"android": {
"sourceDir": "path/react-native-cxx-turbomodule/cpp",
"packageImportPath": null,
"packageInstance": null,
"buildTypes": [],
"libraryName": "RNCxxTurbomoduleSpec",
"componentDescriptors": [],
"cmakeListsPath": "path/react-native-cxx-turbomodule/cpp/build/generated/source/codegen/jni/CMakeLists.txt",
"cxxModuleCMakeListsModuleName": "CxxTurbomodule",
"cxxModuleCMakeListsPath": "path/react-native-cxx-turbomodule/cpp/CMakeLists.txt",
"cxxModuleHeaderName": "CxxTurbomodule",
"isPureCxxDependency": true
}
…ava packagelist This also ignores them from getting included with gradle dependencies
|
Just a heads up that if we merge this, the same functionality needs to be backported here: |
|
@cortinico is there any design doc around autolinking in the core RN repo? Does it clash somehow with RNCCLI autolinking, doing redundant work, bailing out? |
thymikee
left a comment
There was a problem hiding this comment.
@atlj thanks for sending this! We have some docs around autolinking in https://github.com/react-native-community/cli/blob/main/docs/autolinking.md which includes other cxx stuff. Would you mind extending the docs with isPureCxxDependency and how and when to use it from a user perspective?
Nope I don't have a design doc sadly, but I just ported over all the code from We should update |
|
Thanks, that makes it clearer I think! So we keep autolinking until it's deployed in the core (0.75?) and once it has parity, we can start removing it from this codebase? |
We can keep it around, I was actually thinking about updating the |
|
Thanks @atlj! Please contact Nico on how this can be ported to the RNGP in core repo |
|
@atlj can you open an issue on github.com/facebook/react-native to keep track of this upstreaming? |
|
Pick for core is here reactwg/react-native-releases#375 |
|
Hi @atlj, just checking in here before I file a bug report upstream. Does this still work in react-native 0.75+? However, on Android I get error on the new Simply removing |
|
hey @hsjoberg, what's the output of |
|
@szymonrybczak Oh right I forgot to tell about that one. It still interestingly enough reports |
|
@hsjoberg at first look output looks right 🤔 maybe it's something in new autolinking integration in React Native Core? @cortinico any ideas? |
Yeah. 🤔 I think there has been a regression recently. Mind you, it all works well if I delete |
Can very much be. I definitely ported this feature inside RNGP but it can be we missed a parameter of a field somewhere. @hsjoberg Is |
|
@cortinico It is public yes, https://github.com/hsjoberg/react-native-turbo-lnd, but not deployed to npm. But please instead see the small reproducer project I made here: https://github.com/hsjoberg/rn75autolinkregression |
|
@cortinico FYI, I believe I found the problem. I've submitted a pull request to the react-native repo. |
) Summary: Hey. The react-native gradle plugin didn't properly filter out [Pure](react-native-community/cli#2387) C++ TurboModules for autolinking, which caused build failures as a non-existing gradle dependency would be emitted. This makes Pure C++ TurboModules work again for Android. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID][FIXED] Fix autolinking issues for Pure C++ TurboModules Pull Request resolved: #46381 Test Plan: https://github.com/hsjoberg/rn75autolinkregression Try running this repro project to observe the error: ``` 1: Task failed with an exception. ----------- * Where: Build file '/Users/coco/Projects/Blixt/rn75autolinkregression/example/android/app/build.gradle' line: 54 * What went wrong: A problem occurred evaluating project ':app'. > Project with path ':react-native-cxx-turbomodule' could not be found in project ':app'. ``` Simply add the 1-line code from this PR to make the build succeed. Cheers. Reviewed By: cipolleschi Differential Revision: D62377757 Pulled By: cortinico fbshipit-source-id: 9e3fa3777b4e6e4d3f2eb0f996ac0ac7676eedbe
) Summary: Hey. The react-native gradle plugin didn't properly filter out [Pure](react-native-community/cli#2387) C++ TurboModules for autolinking, which caused build failures as a non-existing gradle dependency would be emitted. This makes Pure C++ TurboModules work again for Android. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID][FIXED] Fix autolinking issues for Pure C++ TurboModules Pull Request resolved: #46381 Test Plan: https://github.com/hsjoberg/rn75autolinkregression Try running this repro project to observe the error: ``` 1: Task failed with an exception. ----------- * Where: Build file '/Users/coco/Projects/Blixt/rn75autolinkregression/example/android/app/build.gradle' line: 54 * What went wrong: A problem occurred evaluating project ':app'. > Project with path ':react-native-cxx-turbomodule' could not be found in project ':app'. ``` Simply add the 1-line code from this PR to make the build succeed. Cheers. Reviewed By: cipolleschi Differential Revision: D62377757 Pulled By: cortinico fbshipit-source-id: 9e3fa3777b4e6e4d3f2eb0f996ac0ac7676eedbe
) Summary: Hey. The react-native gradle plugin didn't properly filter out [Pure](react-native-community/cli#2387) C++ TurboModules for autolinking, which caused build failures as a non-existing gradle dependency would be emitted. This makes Pure C++ TurboModules work again for Android. ## Changelog: <!-- Help reviewers and the release process by writing your own changelog entry. Pick one each for the category and type tags: [ANDROID|GENERAL|IOS|INTERNAL] [BREAKING|ADDED|CHANGED|DEPRECATED|REMOVED|FIXED|SECURITY] - Message For more details, see: https://reactnative.dev/contributing/changelogs-in-pull-requests --> [ANDROID][FIXED] Fix autolinking issues for Pure C++ TurboModules Pull Request resolved: #46381 Test Plan: https://github.com/hsjoberg/rn75autolinkregression Try running this repro project to observe the error: ``` 1: Task failed with an exception. ----------- * Where: Build file '/Users/coco/Projects/Blixt/rn75autolinkregression/example/android/app/build.gradle' line: 54 * What went wrong: A problem occurred evaluating project ':app'. > Project with path ':react-native-cxx-turbomodule' could not be found in project ':app'. ``` Simply add the 1-line code from this PR to make the build succeed. Cheers. Reviewed By: cipolleschi Differential Revision: D62377757 Pulled By: cortinico fbshipit-source-id: 9e3fa3777b4e6e4d3f2eb0f996ac0ac7676eedbe
Summary:
#2296 adds support for auto-linking C++ turbo modules on Android. However, you would still need a
build.gradlefile for your module to be linked. This is for a couple of reasons:AndroidManifest.xmlfile or abulid.gradlefile,react-native configreturnsnull. See the related line.packageName,react-native configreturnsnull. We don't need thepackageNameproperty since C++ projects are included by their paths. See the related line.PackageList.javafile tries to include and initialize your turbo module as a Java class. See the related line.This PR derives a property called
isPureCxxDependencyfrom a few factors:cxxModuleCMakeListsModuleNameas a truthy value in their configuration.cxxModuleCMakeListsPathas a truthy value in their configuration.cxxModuleHeaderNameas a truthy value in their configuration.build.gradlefile in theirsourceDir(This isandroid/by default) or its subdirectories.AndroidManifest.xmlfile in theirsourceDiror its subdirectories.If all these cases are met, the CLI outputs the
isPureCxxDependencyproperty astrue. This in turn causes thenative-modules.gradlefile not to include this dependency in the generatedPackageList.javafile and the dependency isn't added as a gradle dependency to the app project.Test Plan:
I have created a turbo module using create-react-native-library. Then I linked the CLI and tested the implementation. I've also added react-native-reanimated as a dependency to the project's example app to make sure this implementation doesn't break the existing support for turbo modules.
Checklist